package hui.com.service.impl;

import hui.com.dao.UserDao;
import hui.com.dao.UserLogDao;
import hui.com.model.entity.PermsEntity;
import hui.com.model.entity.RoleEntity;
import hui.com.model.entity.UserEntity;
import hui.com.model.req.users.RequestGetUserRoleAndPerms;
import hui.com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserDao userDao;
    @Override
    public Boolean addUser(UserEntity user) {
        return userDao.addUser(user);
    }

    @Override
    public Boolean updUser(UserEntity user) {
        return userDao.updUser(user);
    }

    @Override
    public List<UserEntity> getUserRoleAndPerms(RequestGetUserRoleAndPerms userRoleAndPerms) {
        if(userRoleAndPerms.getCurrentIndex()==null){
            userRoleAndPerms.setCurrentIndex(0);
        }
        if(userRoleAndPerms.getPageSize()==null){
            userRoleAndPerms.setPageSize(200);
        }
        if(userRoleAndPerms.getName()==null){
            userRoleAndPerms.setName("");
        }
        return userDao.getUserRoleAndPerms(userRoleAndPerms);
    }

    @Override
    public Integer getUserRoleAndPermsPage(RequestGetUserRoleAndPerms userRoleAndPerms) {

        return userDao.getUserRoleAndPermsPage(userRoleAndPerms);
    }

    @Override
    public Boolean addUserRole(Integer UID, Integer[] roleIDArray) {
        return userDao.addUserRole(UID, roleIDArray);
    }

    @Override
    public Boolean deleteUserRole(Integer UID, Integer roleID) {
        return userDao.deleteUserRole(UID, roleID);
    }

    @Override
    public Boolean addUserPerms(Integer UID, Integer[] permsIDArray) {
        return userDao.addUserPerms(UID,permsIDArray);
    }

    @Override
    public Boolean deleteUserPerms(Integer UID, Integer permsID) {
        return userDao.deleteUserPerms(UID, permsID);
    }

    @Override
    public List<PermsEntity> getNotINUserPerms(UserEntity user) {
        return userDao.getNotINUserPerms(user);
    }

    @Override
    public List<RoleEntity> getNotINUserRole(UserEntity user) {
        return userDao.getNotINUserRole(user);
    }
}
